package com.lx.dynamicdatasouce.framework.demo.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.lx.dynamicdatasouce.framework.demo.entity.User;
import com.lx.dynamicdatasouce.framework.demo.mapper.DemoMapper;
import com.lx.dynamicdatasouce.framework.demo.service.IDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lX
 * @version JDK 8
 * @className DemoService (此处以class为例)
 * @date 2024/10/7
 * @description Demo实现类
 */
@Service
public class DemoService implements IDemoService {

    @Autowired
    DemoMapper demoMapper;


    @Override
    @DS("slave") // 从库， 如果按照下划线命名方式配置多个  ， 可以指定前缀即可（组名）
    public List<User> list() {
        return demoMapper.list();
    }

    @Override
    @DS("master")
    public void save(User user) {
        demoMapper.save(user);
    }
}
